package com.cvo.scrumtoolkit.server.domain;

import java.util.List;

import javax.jdo.annotations.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

import com.cvo.scrumtoolkit.server.EMF;
import com.cvo.scrumtoolkit.shared.ProjectProxy;
import com.google.gwt.user.client.Window;






@Entity
public class BacklogItem {
	
	 @Id
	 @Column(name = "id")
	 @GeneratedValue(strategy = GenerationType.IDENTITY)	 
	 private Long Id;
	 
	// @ManyToOne
	 private Project project;
	 
	 @Version
	 @Column(name="version")
	 private Integer version;
	 private String name;
	 private Long projectid;
	 private int prioriteit;
	 private int geschatteTijd;
	 
		
	 public BacklogItem getBacklogItem() {
		 return this;
	 }
	 public String getBacklogItemName() {
		return name;
	 }
	 
	 public BacklogItem setBacklogItemName(String name) {
	    this.name = name;
		return this;
	 }

	 public int getPrioriteit() {
		return prioriteit;
	 }

	 public BacklogItem setPrioriteit(int prioriteit) {
		this.prioriteit = prioriteit;
		return this;
	 }

	 public int getGeschatteTijd() {
		return geschatteTijd;
	 }

	 public BacklogItem setGeschatteTijd(int geschatteTijd) {
		this.geschatteTijd = geschatteTijd;
		return this;
	 }

	 public Integer getVersion() {
		return version;
	 }

	 public void setVersion(Integer version) {
		this.version = version;
	 }

	 public Long getId() {
		return Id;
	 }
	 public Project getProject() {
			return project;
	 }
 
	 public void setProject(Project project) {
		this.project = project;
	 }


	
	 public static List<BacklogItem> findAllBacklogItems(Long proj) {
		    EntityManager em = entityManager();
		    try {
		      @SuppressWarnings("unchecked")
			List<BacklogItem> list = em.createQuery("select o from BacklogItem o where projectId='"+ proj +"'").getResultList();
		      // force to get all the employees
		      list.size();
		      return list;
		    } finally {
		      em.close();
		    }
		  }

		  public static BacklogItem findBacklogItem(Long id) {
		    if (id == null) {
		      return null;
		    }
		    EntityManager em = entityManager();
		    try {
		      BacklogItem backlogItem  = em.find(BacklogItem.class, id);
		      return backlogItem;
		    } finally {
		      em.close();
		    }
		  }

		  public static final EntityManager entityManager() {
		    return EMF.get().createEntityManager();
		  }

		  public void persist() {
		    EntityManager em = entityManager();
		    try {
		      em.persist(this);
		    } finally {
		      em.close();
		    }
		  }

		  public void remove() {
		    EntityManager em = entityManager();
		    try {
		      BacklogItem backlogItem  = em.find(BacklogItem.class, this.Id);
		      em.remove(backlogItem);
		    } finally {
		      em.close();
		    }
		  }
		public Long getProjectId() {
			return projectid;
		}
		public void setProjectId(Long projectId) {
			this.projectid = projectId;
		}
		
		  

	
	 
	 
	 


}
